import axios from 'axios';
const API_HOST = 'http://dami.ifzbs.cn';

const headers = {
  'Content-Type': 'multipart/form-data'
};

const projectId = "72088";

/**
 * 登录
 * @param username 
 * @param password 
 * @returns 
 */
export const login = (username: string, password: string) => {
  const formData = new FormData();
  formData.append('username', username);
  formData.append('password', password);
  return axios.post(`${API_HOST}:8881/public/userLogin`, formData, {
    headers
  });
}

/**
 * 获取登录token
 * @param token 
 * @param authOrderId 
 * @returns 
 */
export const getAuthCode = (token: string, authOrderId: string) => {
  const formData = new FormData();
  formData.append('token', token);
  formData.append('orderId', authOrderId);
  return axios.post(`${API_HOST}:8884/public/getresult`, formData, {
    headers
  });
}

/**
 * 获取订单信息
 * @param token 
 * @param authOrderId 
 * @returns 
 */
export const getOrderInfo = (token: string, authOrderId: string) => {
  const formData = new FormData();
  formData.append('token', token);
  formData.append('orderId', authOrderId);
  return axios.post(`${API_HOST}:8881/public/getorderinfo`, {
    headers
  });
}

/**
 * 创建二维码任务
 * @param token 
 * @param qrCode 
 * @returns 
 */
export const createTaskApi = (token: string, qrCode: string) => {
  const formData = new FormData();
  formData.append('token', token);
  formData.append('appId', projectId);
  formData.append('qrCode', qrCode);
  return axios.post(`${API_HOST}:8881/createTaskApi`, formData, {
    headers
  });
}